package data;

import models.News;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyOpts;
import com.googlecode.objectify.ObjectifyService;

public class NewsData {
	private static Objectify ofy;
	
	public NewsData() {
		try {
			ObjectifyService.register(News.class);
		} catch (Exception e) {
			//e.printStackTrace();
		}
		ObjectifyOpts opts = new ObjectifyOpts().setSessionCache(true);
		ofy = ObjectifyService.begin(opts);
	}
	
	public void insert(News news) {
		ofy.put(news);
	}
	
	public News getById(String newsId) {
		News news = new News();
		try {
			news = ofy.get(new Key<News>(News.class, newsId));
		} catch (Exception e) {
			news = null;
		}
		return news;
	}
}